from django.db import models

class Users(models.Model):
    phone = models.CharField('手机号', max_length=11)

    def __str__(self):
        return self.phone

    class Meta:
        db_table = 'bq_user'

class UserInfo(models.Model):
    user = models.ForeignKey('Users', on_delete=models.SET_NULL, null=True)
    name = models.CharField('姓名', max_length=12)

    class Meta:
        db_table = 'bq_user_info'

class Proxys(models.Model):
    phone = models.CharField('手机号', max_length=11)
    proxy_name = models.CharField('姓名', max_length=10)
    proxy_type = models.IntegerField('代理类型')
    big_proxy_id = models.IntegerField('大代理')

    class Meta:
        db_table = 'bq_qhtech_proxy'

class Teams(models.Model):
    name = models.CharField('名称', max_length=32)
    area_code = models.CharField('地区', max_length=10)

    class Meta:
        db_table = 'bq_team'

class ProxyTeamUser(models.Model):
    user = models.ForeignKey("Users", on_delete=models.SET_NULL, null=True, verbose_name='店员')
    team = models.ForeignKey("Teams", on_delete=models.SET_NULL, null=True, verbose_name='商户')
    proxy = models.ForeignKey("Proxys", on_delete=models.SET_NULL, null=True, verbose_name='代理')

    class Meta:
        db_table = 'bq_qhtech_proxy_team_user'

class AdminUsers(models.Model):
    name = models.CharField('姓名', max_length=12)

    class Meta:
        db_table = 'bq_admin_users'

class Promotions(models.Model):
    proxy = models.ForeignKey("Proxys", on_delete=models.SET_NULL, null=True)
    admin_user = models.ForeignKey("AdminUsers", on_delete=models.SET_NULL, null=True)

    class Meta:
        db_table = 'bq_promotion'

class QqOrder(models.Model):
    origin_type = models.IntegerField()
    task_status = models.IntegerField()

    class Meta:
        db_table = 'bq_qhtech_coin_glide'

class JieMu(models.Model):
    title = models.CharField('标题', max_length=255)

    def __str__(self):
        return self.title

    class Meta:
        db_table = 'bq_lanmu_jiemu_detailed'

class JiemuRecords(models.Model):
    user = models.ForeignKey("Users", on_delete=models.SET_NULL, db_column='userid', null=True, verbose_name='店员')
    jiemu = models.ForeignKey("JieMu", on_delete=models.SET_NULL, db_column='jiemuid', null=True, verbose_name='节目')
    create_time = models.DateTimeField('播放时间')

    class Meta:
        db_table = 'bq_lanmu_recording'
        verbose_name_plural = u'教售说记录'

class JiemuOrder(models.Model):
    user = models.ForeignKey("Users", on_delete=models.SET_NULL, null=True, verbose_name='店员')
    jiemu = models.ForeignKey("JieMu", on_delete=models.SET_NULL, db_column='detailed_id', null=True, verbose_name='节目')
    buy_time = models.DateTimeField('购买时间')
    pay_method = models.CharField(max_length=1)
    pay_amount = models.FloatField('金额')

    def pay_method_colored(self):
        method_color = '其他'
        if self.pay_method == '1':
            method_color = '余额'
        elif self.pay_method == '2':
            method_color = '支付宝'
        elif self.pay_method == '3':
            method_color = '微信'
        return method_color

    class Meta:
        db_table = 'bq_lanmu_order'
        verbose_name_plural = u'教售说购买记录'